package com.shrct.businessprocess.organization.impl;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.RCEmployeeUser;
import com.shrct.businessprocess.organization.proxy.RCEmployeeProxy;
import edu.fudan.langlab.domain.organization.impl.PartyImpl;
import edu.fudan.langlab.domain.security.User;
import edu.fudan.mylang.pf.IGenericQuery;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCEMPLOYEE_TYPE")
public class RCEmployeeImpl extends PartyImpl implements RCEmployee {
  public RCEmployeeImpl() {
    super();
  }
  
  private String eid;
  
  public String getEid() {
    return this.eid;
  }
  
  public RCEmployee setEid(final String eid) {
    this.eid = eid;
    return this;			
    
  }
  
  private String comment;
  
  public String getComment() {
    return this.comment;
  }
  
  public RCEmployee setComment(final String comment) {
    this.comment = comment;
    return this;			
    
  }
  
  @JoinColumn(name = "directManager_id")
  @ManyToOne(targetEntity = RCEmployeeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCEmployee directManager;
  
  public RCEmployee getDirectManager() {
    return this.directManager;
  }
  
  public RCEmployee setDirectManager(final RCEmployee directManager) {
    this.directManager = directManager;
    return this;			
    
  }
  
  private Boolean isLeave = Boolean.valueOf(false);
  
  public Boolean getIsLeave() {
    return this.isLeave;
  }
  
  public RCEmployee setIsLeave(final Boolean isLeave) {
    this.isLeave = isLeave;
    return this;			
    
  }
  
  public User asUser() {
    IGenericQuery<RCEmployeeUser> query=getObjectFactory().createGenericQuery(RCEmployeeUser.class,"select e from com.shrct.businessprocess.organization.impl.RCEmployeeUserImpl as e   where ((e.employee) = (:this)) and  e.active = 1      ").setParameter("this",this);
    RCEmployeeUser _uniqueResult = query.uniqueResult();
    return _uniqueResult;
  }
  
  public void leave() {
    this.isLeave = Boolean.valueOf(true);
  }
  
  public static RCEmployee create(final IObjectFactory objectFactory) {
    com.shrct.businessprocess.organization.RCEmployee rCEmployee = new com.shrct.businessprocess.organization.impl.RCEmployeeImpl(
    );
    objectFactory.create(rCEmployee);
    return rCEmployee;			
    
  }
  
  public static RCEmployee createRCEmployeeImpl(final IObjectFactory objectFactory, final Procedure1<RCEmployee> init) {
    com.shrct.businessprocess.organization.RCEmployee rCEmployee = new com.shrct.businessprocess.organization.impl.RCEmployeeImpl(
    );
    objectFactory.create(rCEmployee);
    init.apply(rCEmployee);
    
    return rCEmployee;			
    
  }
  
  public RCEmployeeProxy toProxy() {
    com.shrct.businessprocess.organization.proxy.RCEmployeeProxy proxy = new com.shrct.businessprocess.organization.proxy.RCEmployeeProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
